class Solution(object):
    def uniqueLetterString(self, s):
        n = len(s)
        ans = 0
        st = {}
        now = 0
        p = [-1] * n
        for i in range(n):
            if s[i] in st:
                p[i] = st[s[i]]
            st[s[i]] = i
        for i in range(n):
            if p[i] == -1:
                now += i + 1
            else:
                now += i - p[i]
                last_index = p[i]
                if p[last_index] == -1:
                    now = now - last_index - 1
                else:
                    now = now - (last_index - p[last_index])
            ans += now
        return ans


data = Solution()
s = "AAA"
print(data.uniqueLetterString(s))
